package com.cupster.litepaldemo;

import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.cupster.func_db_litepal.crud.UserHelper;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity implements View.OnClickListener {

    TextView mTv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mTv = findViewById(R.id.tv_show);
        findViewById(R.id.btn_add).setOnClickListener(this);
        findViewById(R.id.btn_delete).setOnClickListener(this);
        findViewById(R.id.btn_update).setOnClickListener(this);
        findViewById(R.id.btn_query).setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.btn_add:
                UserHelper.insert("Cupster" ,"18960222222");
                break;
            case R.id.btn_delete:
                UserHelper.delete(1);
                break;
            case R.id.btn_update:
                UserHelper.update(1,"Cupster改");
                break;
            case R.id.btn_query:
                mTv.setText(UserHelper.queryAll());
                break;
        }
    }
}